package org.teststack.Api.Sl.MCcc;

import com.jayway.restassured.RestAssured;
import com.jayway.restassured.response.Response;
import org.apache.commons.codec.net.URLCodec;
import org.teststack.Api.RestClient;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

import static org.teststack.Api.CookieManager.cookies;


public class McYz {//名称查重

    public static void main(String[] args) throws UnsupportedEncodingException {
        mcyz();//12457
    }


    public static int mcyz() throws UnsupportedEncodingException {
        // 登录并更新cookies
        RestClient.loginAndUpdateCookies("liutao", "xQ5Vea/L3CMRNEwoBESSZGSVCnValY4kZcAYe3153B9/dXpazZRG8VLEuMhJdW1RhdZ/cqdUq/5FUdAxeKzdWOmZEj0sVlobwrqzRMgrIPsvyp03QTktVYRUAgloA924e5wLLSx8ECJ4WpUAB8zUa41GkyURFmyVtwxQ3EkLuabQ7V24L8EdzRfBHnFd8zRRd4RkncACXO88rrb4U7uR10ANvR0K4N2Kiai901pyztSuMfXP0fVRBW1lKj+kIONtFufTZoAL48++Q6VVr3r5B9tIC4kkwv0WzQxeOubbVKTNUi1JGnS2CEPPqjuXWJnUAO3u5PRxXmtH5+JN8yXygw==");



        String nameXzqh = "浙江";
        String nameZh = "非脚后跟";
        String nameHy = "建筑设计事务所";
        String nameZzxs = "有限责任公司";

        String nameQc = "浙江非脚后跟建筑设计事务所有限责任公司";
        String S_PROLOC = "浙江省杭州市上城区笕桥街道";
        String S_NAME = "建筑";
        String zyyw = "工程设计活动";

        URLCodec urlCodec = new URLCodec();
        String encodedParam = URLEncoder.encode(nameXzqh, "UTF-8");
        String encodedParam1 = URLEncoder.encode(nameZh, "UTF-8");
        String encodedParam2 = URLEncoder.encode(nameHy, "UTF-8");
        String encodedParam3 = URLEncoder.encode(nameZzxs, "UTF-8");
        String encodedParam4 = URLEncoder.encode(nameQc, "UTF-8");
        String encodedParam5 = URLEncoder.encode(S_PROLOC, "UTF-8");
        String encodedParam6 = URLEncoder.encode(S_NAME, "UTF-8");
        String encodedParam7 = URLEncoder.encode(zyyw, "UTF-8");
        String formData = "method=enterMczzcc&csrftoken=&nameXzqh=" + encodedParam +"&nameHhlx=&nameZh=" + encodedParam1 +"&nameHy=" +encodedParam2 + "&nameZzxs=" + encodedParam3 + "&nameQc=" +encodedParam4 + "&nameList=&mcjbxx=&sbid=&name_id=&pripid=&basemcclsm=&clidsm=&S_PROLOC_PROVINCE=330000&S_PROLOC_CITY=330100&S_PROLOC_DISTRICT=330102&S_PROLOC_STREET=330102016&S_PROLOC_LOCATION=&S_PROLOC=" + encodedParam5 + "&S_QYZTLX=01&S_REGCAP=&S_MCZZXS="+ encodedParam3 +"&S_QYLXDL=11&S_ENTTYPE=1100&S_ZCZJ=&S_RJCZE=&S_CZE=&S_SJQYENTNAME=&S_SJQYUNISCID=&S_COMMITLETTER=&S_ZZSIGN=hz&S_GMLX=0&S_TRADPINY=ELABOBANDAO&S_MCHYSIGN=1&S_HYDL=M&S_HYZL=7400&S_HYXL=7484&S_ISPCOM=2&S_ISQZSP=undefined&xzqh=" + encodedParam + "&mchy=" +encodedParam2+  "&zzxs=" +encodedParam3 + "&zyyw="   +   encodedParam7 + "&xzqhwz=0&sbms=1&ljmsign=&znspsign=0&thsign=&ghcomboid=&ghopscope=&gzqsign=&pri_pripid=&zrzysx=&qylx=qy&gtscmc=&zwzh=" + encodedParam1 + "&S_NAME=" + encodedParam6 + "&zzxs-qylx-nwz=nz&zzxs-qylx=yx&wzmc=1&S_ITENAME=&S_ITEREGNO=&csrftoken=";
//        Map<String, String> formParams = new HashMap<>();
//        formParams.put("method", "enterMczzcc");
//        formParams.put("nameXzqh", "浙江");
//        formParams.put("nameZh", "发货的说法还是的");
//        formParams.put("nameHy", "建筑设计事务所");
//        formParams.put("nameQc", "浙江发货的说法还是的建筑设计事务所有限公司");
//        formParams.put("S_PROLOC_PROVINCE", "330000");
//        formParams.put("S_PROLOC_CITY", "330100");
//        formParams.put("S_PROLOC_DISTRICT", "330102");
//        formParams.put("S_PROLOC_STREET", "330102001");
//        formParams.put("S_PROLOC", "浙江");
//        formParams.put("nameZh", "浙江省杭州市上城区清波街道");
//        formParams.put("S_QYZTLX", "01");
//        formParams.put("S_QYLXDL", "11");
//        formParams.put("S_ENTTYPE", "1100");
//        formParams.put("S_ZZSIGN", "hz");
//        formParams.put("S_GMLX", "0");
//        formParams.put("S_TRADPINY", "FAHUODEYUEFAHUANSHIDE");
//        formParams.put("S_MCHYSIGN", "1");
//        formParams.put("S_HYDL", "M");
//        formParams.put("S_HYZL", "7400");
//        formParams.put("S_HYXL", "7484");
//        formParams.put("S_ISPCOM", "2");
//        formParams.put("S_ISQZSP", "undefined");
//        formParams.put("xzqh", "浙江");
//        formParams.put("mchy", "建筑设计事务所");
//        formParams.put("zzxs", "有限公司");
//        formParams.put("zyyw", "工程设计活动");
//        formParams.put("xzqhwz", "0");
//        formParams.put("sbms", "1");
//        formParams.put("znspsign", "0");
//        formParams.put("qylx", "qy");
//        formParams.put("zwzh", "发货的说法还是的");
//        formParams.put("S_NAME", "建筑");
//        formParams.put("zzxs-qylx-nwz", "nz");
//        formParams.put("zzxs-qylx", "yx");
//        formParams.put("zzxs-zzxs", "on");
//        formParams.put("wzmc", "1");






//        System.out.println(formData);
        // 注意：这里我们仍然将参数放在查询字符串中，尽管这是一个POST请求
        // 如果API设计为接受查询参数，则这是可以的；否则，应考虑将参数放在请求体中
        Response response = RestAssured.given()
                .body(formData)
                .cookies(cookies)
//                .header("Cache-Control","max-age=0")
                .header("Content-Type","application/x-www-form-urlencoded")
//                .header("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7")
                .baseUri("http://10.1.10.141:9031")
                .post("/ywtSldj.do?method=doMczzcc_zjsj&S_ITE=0"); // 假设这里有一个有效的CSRF Token或它是不必要的

        int statusCode = response.getStatusCode();

        System.out.println("Status Code: " + statusCode);


//        int chunkSize = 1000; // 每次打印的字符数
//        for (int start = 0; start < body.length(); start += chunkSize) {
//            int end = Math.min(body.length(), start + chunkSize);
//            System.out.println(body.substring(start, end));
//        }

//        if (body != null) {
//            System.out.println("Response Body: " + body);
//        } else {
//            System.out.println("Response Body is null");
//        }

        return statusCode;

    }
}
